package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//执行查询的操作
public class JDBCDemo05 {
    public static void main(String[] args) {
        //查看所有老师的名字，工资，性别，职称
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT name,salary,gender,title " +
                         "FROM teacher";
            ResultSet rs = statement.executeQuery(sql);//返回的是一个集合
            //需要遍历集合查看数据
            //判断是否有下一个
            while (rs.next()){
                //有就读取里面的字段，括号里的名字是数据的字段名
                String name = rs.getString("name");
                int salary = rs.getInt("salary");
                String gender = rs.getString("gender");
                String title = rs.getString("title");
                System.out.println(name +"," +salary+","+gender+","+title);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
